#include "UButton.h"
#include "UControl.h"

#define StippleY 5
#define StippleX 5

TButton::TButton(TRectangle rect)
: TControl(rect)
{
	Pressed = false;
}

void TButton::DrawFocusStippleLine()
{
	glColor3f(0,0,0);
	if (IsFocussed())
	{
		glEnable(GL_LINE_STIPPLE);
		glLineStipple(1, 0x1111);//  dotted
		glBegin(GL_LINE_LOOP);
			glVertex2i(Left	 + StippleX, Top + StippleY);
			glVertex2i(Right - StippleX, Top + StippleY);
			glVertex2i(Right - StippleX, Bottom-StippleY);
			glVertex2i(Left  + StippleX, Bottom-StippleY);
		glEnd();
		glDisable(GL_LINE_STIPPLE);
	}
}


void TButton::MouseDown(int X, int Y, uint8 button)
{
	TControl::MouseDown(X, Y, button);
	Pressed = true;
}

void TButton::MouseUp(int X, int Y, uint8 button)
{
	TControl::MouseUp(X, Y, button);
	Pressed = false;
	LastClickWasOurs = false;
}

void TButton::MouseClick()
{
	if (onClick)
		onClick();
}

void TButton::MouseLeave()
{
    TControl::MouseLeave();
    Pressed = false;
}

void TButton::MouseMove(int X, int Y, int mstate)
{
    TControl::MouseMove(X, Y, mstate);
    if (LastClickWasOurs)
        Pressed = true;
}
